package jvlc;



import org.videolan.jvlc.JVLC;
import org.videolan.jvlc.VLCException;

public class MyPlayerVLC {

	private JVLC jvlc;
	private boolean videoInput;
	
	public MyPlayerVLC(String[] args) {
		videoInput = false;
		jvlc = new JVLC(args);
		
		try {
			//Adicionando arquivos a playlist do jvlcw
			jvlc.playlist.add("file://video.avi", "video.avi");
			jvlc.playlist.add("file://audio.mp3", "audio.mp3");
			jvlc.playlist.play(-1, null);
		} catch (VLCException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		//Testar algumas funcionalidades e m�todos
		
		try {
        	Thread.sleep(5000);
        	if (jvlc.hasVout()) videoInput = true;
		} catch (InterruptedException e) {
				e.printStackTrace();
		}
		
		//Analisando dimens�es do v�deo
		if (videoInput) {
        	try {
        		System.out.println("Largura do v�deo ==> " + jvlc.video.getWidth());
        		System.out.println("Altura do v�deo ==> " + jvlc.video.getHeight());
        	} catch (VLCException e) {
        		e.printStackTrace();
        	}
        }
		
		//Trabalhando com FullScreen
    	System.out.print("5 segundos para Fullscreen... ");        	
    	
    	try {
			Thread.sleep(5000);
		
	    	jvlc.video.setFullscreen(true);
	    	Thread.sleep(5000);
	    	jvlc.video.setFullscreen(false);
	    	
			//Dimens�es de tempo do v�deo
			long time = 6*10000;
			System.out.println("Setando o v�deo 30 segundos a frente");
			jvlc.input.setTime(time);
	
			Thread.sleep(5000);
	           
	       	System.out.print("Obtendo snapshot... ");
	       	jvlc.video.getSnapshot( System.getProperty( "user.dir" ) + "/snap.png");
	       	System.out.println("Obtido. (Imagem armazenada em " + 
	       			System.getProperty( "user.dir" ) + "/snap.png )");
	   		Thread.sleep(9000);
	           System.out.println("Redimensionando para 300x300");
	           jvlc.video.setSize(300, 300);
	           Thread.sleep(5000);
    	} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (VLCException e) {
			e.printStackTrace();
		}
		
		//Configurando o som
		System.out.print("Muting...");
        try {
			jvlc.audio.setMute(true);
	        Thread.sleep(6000);
	        System.out.println("unmuting.");
	        jvlc.audio.setMute(false);
	        Thread.sleep(3000);
	        System.out.println("Volume �: " + jvlc.audio.getVolume());
	        System.out.print("Setando volume para 150... ");
	        jvlc.audio.setVolume(150);
	        System.out.println("OK!");
	        Thread.sleep(3000);
	        System.out.print("Normalizando volume... ");
	        jvlc.audio.setVolume(50);
        } catch (VLCException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		//Informa��es do v�deo
		System.out.println("INPUT INFORMATION");
        System.out.println("-----------------");
        try {
			System.out.println("Total length   (ms) :\t" + jvlc.input.getLength());
			System.out.println("Input time     (ms) :\t" + jvlc.input.getTime());
			System.out.println("Input position [0-1]:\t" + jvlc.input.getPosition());
        	System.out.println("Input FPS          :\t" + jvlc.input.getFPS());
        	Thread.sleep(9000);
        } catch (VLCException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
        
        System.out.println("Tocando pr�ximo item da playlist...");
        
        try {
    		jvlc.playlist.next();
    		System.out.println("Tocando item 2...");
    	} catch (VLCException e) {
    		e.printStackTrace();
    	}
    	
    	try {
    		Thread.sleep(60000);
    	} catch (InterruptedException e) {
    		e.printStackTrace();
    	}
    	jvlc.destroy();
	}

	public static void main(String[] args) {
		new MyPlayerVLC(args);
	}

}
